package com.gao.ranklist.service;

import com.gao.ranklist.service.impl.HotSearchRanklistServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 执行定时任务
 */
@Component
public class SchedulerTask {
    Logger logger = LoggerFactory.getLogger(SchedulerTask.class);

    @Autowired
    private HotSearchRanklistServiceImpl service;

    /**
     * fixedDelay 和 cron 表达式都可以
     */
    @Scheduled(fixedDelay = 5*60*1000)
    public void scheduled1() {
        logger.info("每5分钟刷新一次数据");
        service.refreshHour();
    }

    @Scheduled(cron = "0 0 0/1 * * ?")
    public void scheduled2() {
        logger.info("每小时刷新一次数据");
        service.autoRefreshData();
    }
}
